import { Component, OnInit, Input } from '@angular/core';
import { UserService } from 'src/app/service/user.service';
import { YearawardService } from '../yearaward.service';
import { BaseService } from 'src/app/service/base.service';
import { UtilsService } from 'src/app/service/utils.service';
@Component({
  selector: 'app-xinxiu',
  templateUrl: './index.component.html',
  styleUrls: ['./index.component.scss'],
})
export class XinxiuComponent implements OnInit {
  @Input() timeConfig: any[] = [];
  /* ___ _ ___ */
  public deployUrl: string; /* 资源地址前缀 */
  /* ___ _ ___ */
  public tabs: EndYear.ITAB[] = [
    {
      status: 1,
      key: 1,
      type: 29,
      stageId: undefined,
      startTime: undefined,
      endTime: undefined,
    },
  ]; /* tabs */
  /* ___ _ ___ */
  public curTabKey = 1; /* 当前tab 1晋级赛 2决赛 3结束 */

  constructor(
    private userService: UserService,
    private yearawardService: YearawardService,
    private baseService: BaseService,
    private utilsservice: UtilsService
  ) {}

  ngOnInit(): void {
    // 获取
    this.deployUrl = this.userService.getDeployUrl();
    this.checkChildren();
  }

  /**
   * 计算当前活动阶段
   */
  public checkChildren() {
    const children = this.baseService.useStatusWithTargetTypes(
      this.timeConfig,
      29,
      30
    );
    this.tabs = children;
    // console.log('tabs=>', children);
    for (const child of children) {
      if (child.status === 2 && child.type === 29) {
        //晋级赛
        this.curTabKey = 1;
        console.log('=>', '新秀榜 晋级赛');
      }
      if (child.status === 2 && child.type === 30) {
        //决赛
        this.curTabKey = 2;
        console.log('=>', '新秀榜 决赛');
      }
    }

    // 两者都结束 定位决赛
    if (children.every((child) => child.status === 3)) {
      this.curTabKey = 2;
      console.log('均结束=>', '新秀榜 决赛');
    }
  }

  /**
   * @param tab 当前tab
   * @description: 切换tab
   */
  onTabClick(tab) {
    const { status, key } = tab;
    if (status === 1) {
      // 未开始
      this.baseService.showToast('活动暂未开始', 1500);
    } else {
      this.curTabKey = key;
    }
  }
}
